﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Patient : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string Card = Request.QueryString["IDCard"];
            string sql = string.Format("select * from Patient where IDCard='{0}'", Card);
            SqlDataReader dr = DBHelper.GetDataReader(sql);
            while (dr.Read())
            {
                LblName.Text = dr["Name"].ToString();
                LblPhone.Text = dr["Phone"].ToString();
                LblSex.Text = dr["Sex"].ToString();
                LblAge.Text = dr["Age"].ToString();
            }
            LblIDCard.Text = Card;
            dr.Close();
        }
    }
    string Name = "";
    protected void TxtName_TextChanged(object sender, EventArgs e)
    {
        string sql = string.Format("select * from DrugDict where ComName like'%{0}%'",TxtName.Text);
        SqlDataReader dr = DBHelper.GetDataReader(sql);
        
        while (dr.Read())
        {
            LblSpec.Text = dr["Spec"].ToString();
            LblPrice.Text =dr["Priceinfo"].ToString();
            Name = dr["ComName"].ToString();
        }
        dr.Close();
        TxtName.Text = Name;
    }

    protected void BtnTjCf_Click(object sender, EventArgs e)
    {
        string Yas = DropDownList1.SelectedValue;
        if (Yas == "是")
        {
            if (TxtSymptom.Text == "" && TxtDiagnosis.Text == "")
            {
                Response.Write("<script> alert('保存失败，症状或诊断不能为空!') </script>");
            }
            else
            {
                string Doc=Session["Name"].ToString();
                string sql = string.Format("insert into Hospitalizat (DocID,PatIDCard,Symptom,Diagnosis,DocOrder) values('{0}','{1}','{2}','{3}','{4}')", Doc, LblIDCard.Text, TxtSymptom.Text, TxtDiagnosis.Text, TxtOrder.Text);
                DBHelper.GetNonQuery(sql);
                Response.Write("<script>alert('保存成功！');window.location.href='Seek.aspx';</script>");
            }
        }
        else if (Yas == "否")
        {
            if (TxtSymptom.Text == "" && TxtDiagnosis.Text == "")
            {
                Response.Write("<script> alert('保存失败，症状或诊断不能为空!') </script>");
            }
            else
            {
                string Doc = Session["Name"].ToString();
                string sql = string.Format("insert into Seek (DocID,IDCard,Symptom,Diagnosis,DocOrder) values('{0}','{1}','{2}','{3}','{4}')", Doc, LblIDCard.Text, TxtSymptom.Text, TxtDiagnosis.Text, TxtOrder.Text);
                DBHelper.GetNonQuery(sql);
                string updatesql = string.Format("update Register set VisStatus='已就诊' where PatIDCard='{0}' and DocID='{1}'", LblIDCard.Text, Doc);
                DBHelper.GetNonQuery(updatesql);
                Response.Write("<script>alert('保存成功！');window.location.href='Seek.aspx';</script>");
            }
        }
        
    }


    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("SelectDrugs.aspx");
    }

    protected void BtnYY_Click(object sender, EventArgs e)
    {
        if (TxtName.Text == "" && TxtDosage.Text == "" && TxtQuantity.Text == "")
        { 
            Response.Write("<script> alert('药品添加失败，信息不能为空!') </script>");
        }
        else
        {
            string Doc = Session["Name"].ToString();
            string insertsql = string.Format("insert into Bill (DocID,IDCard,ComName,Specifications,Consumption,Quantity,Price) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", Doc, LblIDCard.Text, TxtName.Text, LblSpec.Text, TxtDosage.Text, TxtQuantity.Text, LblPrice.Text);
            DBHelper.GetNonQuery(insertsql);
            Response.Write("<script> alert('药品添加成功!') </script>");
            LblSpec.Text = "";
            TxtName.Text = "";
            TxtDosage.Text = "";
            TxtQuantity.Text = "";
            LblPrice.Text = "";
        }
    }
}